<?php
function new_excerpt_more() {
    return ' <a href="'. get_permalink() . '"> <b>...Read the Rest</b></a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

function mytheme_comment($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment; ?>
    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    <div id="comment-<?php comment_ID(); ?>">
	<a class="gravatar">
	    <?php echo get_avatar($comment,$size='60'); ?>
	</a>
	<div class="commentbody">
	    <cite><?php comment_author_link() ?></cite>
	    <?php if ($comment->comment_approved == '0') : ?>
		<em>Your comment is awaiting moderation.</em>
	    <?php endif; ?>
	    <br />
	    <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> on <?php comment_time() ?></a> <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?></small>
	    <?php comment_text() ?>
	</div>
	<div class="clear"></div>
	<div class="reply">
	    <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
	</div>
    </div>
<?php
}

function mytheme_ping($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment; ?>
    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    <div id="comment-<?php comment_ID(); ?>">
	<div class="commentbody">
	    <cite><?php comment_author_link() ?></cite>
	    <?php if ($comment->comment_approved == '0') : ?>
		<em>Your comment is awaiting moderation.</em>
	    <?php endif; ?>
	    <br />
	    <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> on <?php comment_time() ?></a> <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?></small>
	    <?php comment_text() ?>
	</div>
    </div>
<?php
 }

if ( function_exists( 'add_theme_support' ) ){
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( itx_get_option('front','thumbx'), itx_get_option('front','thumby'), true );
    add_image_size('featured', itx_get_option('front','featuredx'), itx_get_option('front','featuredy'),true);
}

function itx_content($class=false){
    global $post;
?>
    <div <?php post_class($class) ?>>
    <?php
	if ($class=='featured'){add_filter('excerpt_length', 'itx_featured_length');$thumb=itx_thumbnail(1);$class='itx-featured';}
	else {add_filter('excerpt_length', 'itx_excerpt_length');$thumb=itx_thumbnail();$class='itx-thumb';}
        if(itx_get_option('front','not')||$thumb) $tclass='thumb'; else $tclass='nothumb';
    ?>
        <div class="postwrap <?php echo $tclass?>">
	    <div class="thumbwrap">
		<div class="<?php echo $class ?>">
		<?php echo $thumb;?>
		</div>
		<div class="meta">
		    <div class="time"><?php the_time(get_option('date_format')); ?></div>
		    <div class="commentcount"><span class="ui-icon ui-icon-comment"></span><?php if (!post_password_required())comments_popup_link('0','1', '%','',''); ?></div>
		</div>
	    </div>
	    <div class="entry">
		<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
		<?php the_excerpt();?>
	    </div>
        </div>
    </div>
<?php
}

function itx_line_content($class=false){
   global $post;
?>
    <div <?php post_class($class) ?>>
	<div class="bcats"><span class="ui-icon ui-icon-folder-open"></span><span><em>:</em> <?php $c=get_the_category();echo $c[0]->cat_name; ?></span></div>
	<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
	<div class="meta">
	    <div class="time"><?php the_time(get_option('date_format')); ?></div>
	    <div class="commentcount"><span class="ui-icon ui-icon-comment"></span><?php if (!post_password_required())comments_popup_link('0','1', '%','',''); ?></div>
	</div>
    </div>
<?php
}

function itx_single_content($class=false){
   global $post;
?>
    <div <?php post_class($class) ?>>
        <div class="postwrap">
	    <div class="titlewrap">
		<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
		<?php if(comments_open()):?><div class="bcomment"><span class="ui-icon ui-icon-comment"></span><span><?php comments_popup_link('0','1', '%','',''); ?></span></div><?php endif;?>
		<div class="clear"></div>
		<?php if(is_single()):?> <div class="time"><?php the_time(get_option('date_format')); ?></div><?php endif;?>
		<small><?php edit_post_link('Edit this entry?','',''); ?></small>
	    </div>
            <div class="clear"></div>
            <div class="entry">
		<?php the_content();?>
            </div>
            <div class="clear"></div>
            <span class="linkpages"><?php wp_link_pages(); ?></span>
            <div class="clear"></div>
            <?php if (!is_page()){ ?>
            <div class="footmeta">
                <div class="bcats"><span class="ui-icon ui-icon-folder-open"></span><em>:</em> <?php the_category(','); ?></div>
                <?php the_tags('<div class="btags"><span class="ui-icon ui-icon-tag"></span><em>:</em> ', ', ', '</div>'); ?>
            </div>
            <?php } ?>
            <div class="clear"></div>
        </div>
        <?php if (is_singular())comments_template('',true); ?>
    </div>
<?php
}

function itx_archive_title(){
    /* If this is a category archive */ if (is_category()) { ?>
    <h2 class="pagetitle"><?php single_cat_title(); ?></h2>
    <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    <h2 class="pagetitle">Tag: <?php single_tag_title(); ?></h2>
    <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    <h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
    <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    <h2 class="pagetitle">Archive for <?php the_time('F, Y'); ?></h2>
    <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    <h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>
    <?php /* If this is an author archive */ } elseif (is_author()) { ?>
    <h2 class="pagetitle">Author Archive</h2>
    <?php /* If this is a paged archive */ } else{ ?>
    <h2 class="pagetitle">Archives</h2>
    <?php }
}

function itx_notfound(){
	global $post;
    if (is_search()) {
        $something ='<strong>'.get_search_query().'</strong>';
        $here='again';
    } else {
        $something="something";
        $here='here';
    }
    ?>
    <div class="post">
	<h2 class="title"><a href="<?php the_permalink() ?>">Not Found</a></h2>
	<div class="clear"></div>
	<div class="fentry">
	    <p>Sorry, but you are looking for <?php echo $something ?> that isn't here.
		You can search <?php echo $here ?>
	     <?php if (itx_active_widget('search')):?>
		by using <a href="#searchform">this form</a>...
	     <?php else: ?> using the form below <br />
		<?php include (TEMPLATEPATH . '/searchform.php'); endif;?>
	    </p>
	</div>
    </div>
<?php
}

function itx_footer(){
    $da=itx_get_option('vars');
    if ($ech=$da->data) echo $ech.'<!-- Calotropis '.THEME_VERSION." -->\n";
    else echo '<div id="footerright"><strong><a href="http://calotropis.itx.web.id/">Calotropis</a></strong> theme by <a href="http://itx.web.id/">itx</a></div></div></div></div><!-- Calotropis '.THEME_VERSION." noopt -->\n";
}
add_action('wp_footer','itx_footer',1);

function itx_featured_length() {
	return itx_get_option('front','featuredlim');
}

function itx_excerpt_length() {
	return itx_get_option('front','excerptlim');
}

add_action('wp_head','itx_favicon');
add_action('admin_head','itx_favicon');
function itx_favicon(){
    $fav=itx_get_option('misc','favicon');
    if($fav) echo '<link rel="shortcut icon" href="'.$fav.'" />';
}
?>